package com.heima.article.controller;


import com.heima.article.dto.ArticleDto;
import com.heima.article.dto.ArticleHomeDto;
import com.heima.article.dto.ArticleInfoDto;
import com.heima.article.task.ArticleHtmlTasks;
import com.heima.common.dto.ResponseResult;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.article.service.IApArticleService;
import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 文章信息表，存储已发布的文章 前端控制器
 * </p>
 *
 * @author syl
 * @since 2022-06-29
 */
@RestController
@RequestMapping("/api/v1/article")
@Api(tags = "文章信息表，存储已发布的文章接口")
@CrossOrigin
public class ApArticleController{

    @Autowired
    private IApArticleService apArticleService;
/**
 * @description:   app文章详情-功能实现
 * @author: wangjian
        * @date: 2022/7/3 14:34
 * @param: dto
 * @return: com.heima.common.dto.ResponseResult
 **/
 @PostMapping("/load_article_info")
public ResponseResult LoadArticleInfo(@RequestBody ArticleInfoDto dto){
     return apArticleService.loadArticleInfo(dto);
 }






    /**
  * @description:保存文章
  * @author: wangjian
  * @param: dto
  * @return: com.heima.common.dto.ResponseResult<java.lang.Long>
  **/
  @PostMapping
  public ResponseResult<Long> save(@RequestBody ArticleDto dto){
      return apArticleService.saveApArticle(dto);
  }
  /**
   * @description:  首页加载文章 - 更新
   * @author: wangjian
 * @param: dto
 * @return: com.heima.common.dto.ResponseResult
   **/
 @PostMapping("/loadnew")
 public ResponseResult losdNew(@RequestBody ArticleHomeDto dto){
     return  apArticleService.load(dto,0);
 }
 /** 页加载文章 - 更多
  * @description:
  * @author: wangjian
  * @param: dto
  * @return: com.heima.common.dto.ResponseResult
  **/
 @PostMapping("/loadmore")
 public ResponseResult loamore(@RequestBody ArticleHomeDto dto){
     return apArticleService.load(dto,1);
 }





















    @PostMapping
    public ResponseResult<Long> saveApArticle(@RequestBody ArticleDto dto){

        return apArticleService.saveApArticle(dto);
    }
    @PostMapping("/load")
    @ApiOperation(value = "load" ,notes = "首页初次加载文章")
    @ApiModelProperty(name ="dto" ,dataType = "ArticleHomeDto" ,required = true)
    public ResponseResult load(@RequestBody ArticleHomeDto dto){
        return apArticleService.load(dto,0);  //0 代表初次加载或加载更新
    }
    @PostMapping("/loadnew")
    @ApiOperation(value = "loadnew" ,notes = "首页加载更新文章")
    @ApiModelProperty(name ="dto" ,dataType = "ArticleHomeDto" ,required = true)
    public ResponseResult loadnew(@RequestBody ArticleHomeDto dto){
        return apArticleService.load(dto,0); //0 代表初次加载或加载更新
    }
    @PostMapping("/loadmore")
    @ApiOperation(value = "loadmore" ,notes = "首页加载更多文章")
    @ApiModelProperty(name ="dto" ,dataType = "ArticleHomeDto" ,required = true)
    public ResponseResult loadmore(@RequestBody ArticleHomeDto dto){
        return apArticleService.load(dto,1); //1 代表加载更多
    }


    @PostMapping("/load_article_info")
    @ApiOperation(value = "loadArticleInfo" ,notes = "根据id查看文章")
    @ApiModelProperty(name ="dto" ,dataType = "ArticleInfoDto" ,required = true)
    public ResponseResult loadArticleInfo(@RequestBody ArticleInfoDto dto){
        return apArticleService.loadArticleInfo(dto); //根据id查看文章
    }


}
